import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib import rcParams

# 设置字体列表，matplotlib 会自动选择可用的字体
rcParams['font.sans-serif'] = ['Microsoft YaHei', 'Arial Unicode MS', 'SimHei', 'sans-serif']
rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

def draw_architecture_diagram():
    fig, ax = plt.subplots(figsize=(10, 6))

    # 绘制前端部分
    ax.add_patch(patches.Rectangle((0.1, 0.6), 0.3, 0.3, edgecolor='blue', facecolor='lightblue'))
    ax.text(0.25, 0.75, '前端\n(React)', horizontalalignment='center', verticalalignment='center', fontsize=12)

    # 绘制后端部分
    ax.add_patch(patches.Rectangle((0.6, 0.6), 0.3, 0.3, edgecolor='green', facecolor='lightgreen'))
    ax.text(0.75, 0.75, '后端\n(Node.js)', horizontalalignment='center', verticalalignment='center', fontsize=12)

    # 绘制数据库部分
    ax.add_patch(patches.Rectangle((0.35, 0.1), 0.3, 0.3, edgecolor='red', facecolor='lightcoral'))
    ax.text(0.5, 0.25, '数据库\n(Prisma)', horizontalalignment='center', verticalalignment='center', fontsize=12)

    # 绘制箭头
    ax.annotate('', xy=(0.4, 0.75), xytext=(0.6, 0.75), arrowprops=dict(facecolor='black', shrink=0.05))
    ax.annotate('', xy=(0.5, 0.6), xytext=(0.5, 0.4), arrowprops=dict(facecolor='black', shrink=0.05))

    # 设置图表属性
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)
    ax.axis('off')

    plt.title('系统架构图')
    plt.savefig('architecture_diagram.png')
    plt.show()

if __name__ == "__main__":
    draw_architecture_diagram() 